package cn.wubo.base.controller;

import cn.wubo.base.entity.RoleEntity;
import cn.wubo.base.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "角色")
@RestController
@RequestMapping(value = "/role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation(value = "查询", notes = "查询")
    @RequestMapping(value = "/findRoleList",method = RequestMethod.GET)
    public List<RoleEntity> findRoleList(
            @RequestParam(name = "limit", required = false) String limit,
            @RequestParam(name = "offset", required = false) String offset,
            @RequestParam(name = "search", required = false) String search,
            @RequestParam(name = "sort", required = false) String sort,
            @RequestParam(name = "order", required = false) String order
    ) {
        return roleService.findAll();
    }

    @ApiOperation(value = "保存", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public RoleEntity save(
            @RequestBody RoleEntity role
    ) {
        return roleService.saveAndFlush(role);
    }

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @RequestMapping(value = "/deleteInBatch", method = RequestMethod.DELETE)
    @ResponseBody
    public List<RoleEntity> deleteInBatch(
            @RequestBody List<RoleEntity> roles
    ) {
        roleService.deleteInBatch(roles);
        return roles;
    }

}
